﻿using PomposoUniversity.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PomposoUniversity.DataAccess
{
    /// <summary>
    /// Initializes the database with data when the model changes the database schema
    /// </summary>
    public class SchoolInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<SchoolContext>
    {
        /// <summary>
        /// Seeds the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void Seed(SchoolContext context)
        {
            // Create students
            var students = new List<Student>
            {
                new Student
                {
                    FirstMidName = "Raúl",
                    LastName = "Arrivi",
                    EnrollmentDate = new DateTime(2012, 9, 12),
                },
                new Student
                {
                    FirstMidName = "Mar",
                    LastName = "Arrivi",
                    EnrollmentDate = new DateTime(2008, 9, 10),
                },
                new Student
                {
                    FirstMidName = "Rodrigo",
                    LastName = "Astorga",
                    EnrollmentDate = new DateTime(2011, 9, 6),
                },
                new Student
                {
                    FirstMidName = "Emma",
                    LastName = "Astorga",
                    EnrollmentDate = new DateTime(2011, 9, 6),
                },
                new Student
                {
                    FirstMidName = "Eva",
                    LastName = "Almeida",
                    EnrollmentDate = new DateTime(2012, 5, 12),
                },
                new Student
                {
                    FirstMidName = "Rosa",
                    LastName = "Moreno",
                    EnrollmentDate = new DateTime(2013, 3, 11),
                },
            };

            context.Students.AddRange(students);
            context.SaveChanges();

            var courses = new List<Course>
            {
                new Course { CourseID = 1001, Credits = 5, Title = "Programación Orientada a Objetos" },
                new Course { CourseID = 1002, Credits = 7, Title = "Bases de Datos" },
                new Course { CourseID = 1004, Credits = 3, Title = "Redes Neuronales" },
                new Course { CourseID = 2001, Credits = 4, Title = "Seguridad Ciudadana" },
                new Course { CourseID = 2002, Credits = 7, Title = "Defensa Personal" },
                new Course { CourseID = 2004, Credits = 5, Title = "Derecho Civil" },
                new Course { CourseID = 4001, Credits = 6, Title = "Dinámica de Fluidos" },
                new Course { CourseID = 4003, Credits = 6, Title = "Física Mecánica" },
            };

            context.Courses.AddRange(courses);
            context.SaveChanges();

            var enrollments = new List<Enrollment>
            {
                new Enrollment { StudentID = 1, CourseID = 1001, Grade = Grade.A },
                new Enrollment { StudentID = 2, CourseID = 1002, Grade = Grade.D },
                new Enrollment { StudentID = 3, CourseID = 2001, Grade = Grade.C },
                new Enrollment { StudentID = 4, CourseID = 2001, Grade = Grade.D },
                new Enrollment { StudentID = 5, CourseID = 2004, Grade = Grade.B },
                new Enrollment { StudentID = 6, CourseID = 4003, Grade = Grade.B },
            };

            context.Enrollments.AddRange(enrollments);
            context.SaveChanges();

            //base.Seed(context);
        }
    }
}